﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;

namespace sqlTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            try
            {
                BloggingContext db = new BloggingContext();
                db.Blogs.Add(new Blog() { Url = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"), });
                db.SaveChanges();

                BloggingContext db1 = new BloggingContext();
                var lest = db1.Blogs.ToListAsync().Result;
                foreach (var item in lest)
                {
                    Console.WriteLine(item.Url);
                }
            }
            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
            }
        }
    }
    public class BloggingContext : DbContext
    {
        public DbSet<Blog> Blogs { get; set; }
        public DbSet<Post> Posts { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlite("Data Source=blogging.db");
        }
    }

    public class Blog
    {
        public int BlogId { get; set; }
        public string Url { get; set; }

        public List<Post> Posts { get; set; }
    }

    public class Post
    {
        public int PostId { get; set; }
        public string Title { get; set; }
        public string Content { get; set; }

        public int BlogId { get; set; }
        public Blog Blog { get; set; }
    }
}
